<?php
/**
 *  插入分享数据
 */

class InsertShare extends APIBase {
	public $tag = "InsertShare";
	//public $isLogin = false;
	public function before() {
		$this->initMysql();
		$this->initCacheRedis();
		return true;
	}
			
	public function logic() {
	    $pid = $this->param['pid'];//分享者uid
		$sid = $this->param['sid'];//被分享者uid
        $row = $this->mysql->select("sharecount", "*", array('sid'=>$sid));
		if(empty($row)){
			$topid = $this->getTop($pid);
			$id = $this->mysql->insert("sharecount",array('pid'=>$pid,'sid'=>$sid,'status'=>0,'createtime'=>time(),'topid'=>$topid));
		}
	}
	
	public function getTop($pid){
		$row = $this->mysql->select("sharecount","*",array('sid'=>$pid));
		if(!empty($row)){
			return $this->getTop($row[0]['pid']);
		}else{
			return $pid;
		}
	}

	public function after() {
		$this->deinitDataRedis();
		$this->deinitMysql();
	}
}

?>
